package com.jt.controller;

import com.jt.pojo.ItemCat;
import com.jt.service.ItemCatService;
import com.jt.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/itemCat")
public class ItemCatController {
    @Autowired
    private ItemCatService itemCatService;
    @GetMapping("/findAll")
    public List<ItemCat> findAll(){
        return itemCatService.findAll();
    }
    @GetMapping("/findItemCatList/{type}")
    public SysResult findItemCatList(@PathVariable Integer type){
        List<ItemCat> list=itemCatService.findItemCatList(type);

        return SysResult.success(list);
    }
    @PutMapping("/status/{id}/{status}")
    public SysResult status(ItemCat itemCat){
        itemCatService.updatestatus(itemCat.getId(),itemCat.getStatus() );
        return SysResult.success();
    }

    @PostMapping("/saveItemCat")
    public SysResult saveItemCat(@RequestBody ItemCat cat){
        if (itemCatService.insertItemCat(cat)>0){
            return SysResult.success();
        }
        return SysResult.fail();
    }
    @DeleteMapping("/deleteItemCat")
    public SysResult deleteItemCat( Integer id, Integer level){
        System.err.println("id"+id);
        if(itemCatService.deleteItemCat(id,level)>0){
            return SysResult.success();
        };
        return  SysResult.fail();

    }
    @PutMapping("/updateItemCat")
    public SysResult update(@RequestBody ItemCat cat){
        if(itemCatService.updateItemCat(cat)>0)
            return SysResult.success();
        return SysResult.fail();

    }
}
